<?php

namespace App\Http\Controllers\Frontend;


class SearchController extends BaseController
{
    // 搜索 初始化
    public function initialize()
    {
        parent::initialize();
    }

    // 首页
    public function index()
    {
        // 搜索的关键词
        $option  = $this->optLogic();
        $keyword = $option->getData('keyword', null, 'trim');
        $page    = $option->getData('page', 1, 'intval');

        // 传值
        $nextPage = '/search.html?keyword='.urlencode($keyword).'&page='.($page + 1);
        $option->assign('keyword', $keyword);
        $option->assign('nextPage', $nextPage);

        return $this->dispaly('frontend.search');
    }

    // 加载更多
    public function more()
    {
        // 搜索的关键词
        $option  = $this->optLogic();
        $keyword = $option->getData('keyword', null, 'trim');
        $page    = $option->getData('page', 1, 'intval');

        $component = new Components([]);
        $html      = $component->search($keyword);
        $nextPage  = '/search.html?keyword='.urlencode($keyword).'&page='.($page + 1);


        return $this->success(['html' => (string)$html, 'nextUrl' => $nextPage]);
    }

}


